package com.adun.scheduler.local.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author ZDF
 * @date 2025/8/21
 */
@Slf4j
@Component
@Aspect
public class ScheduledAspect {


    @Pointcut("@annotation(org.springframework.scheduling.annotation.Scheduled)")
    public void pointcut() {
    }

    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        // 每次调用执行
        //com.adun.scheduler.local.scheduer.SpringTaskScheduler$$EnhancerBySpringCGLIB$$b45754e6
        // System.out.println(joinPoint.getThis().getClass().getName());
        // com.adun.scheduler.local.scheduer.SpringTaskScheduler
        // System.out.println(joinPoint.getTarget().getClass().getName());
        // method-execution
        // System.out.println(joinPoint.getKind());
        Object target = joinPoint.getTarget();
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Scheduled scheduled = methodSignature.getMethod().getAnnotation(Scheduled.class);
        log.info("Scheduled:{},{},{}",target.getClass().getName(),methodSignature.getName(),scheduled.cron());
    }
}
